package com.dcjt.firehotcarpad.model

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.aries.library.fast.manager.LoggerManager
import com.dcjt.firehotcarpad.entity.BaseEntity
import com.dcjt.firehotcarpad.entity.CjXx
import com.dcjt.firehotcarpad.entity.Sxxx
import com.dcjt.firehotcarpad.retrofit1.repository.ApiRepository1
import io.reactivex.disposables.CompositeDisposable

class FreeDocumentViewModel: ViewModel() {
    private val mCompositeDisposable = CompositeDisposable()
    val requestStatusLiveData: MutableLiveData<BaseEntity<List<Sxxx>>> = MutableLiveData()

    fun getSxhList(zqid:String){
        mCompositeDisposable.add(ApiRepository1.getInstance().getSxhInfoList(zqid).subscribe({
            requestStatusLiveData.postValue(BaseEntity<List<Sxxx>>().also {value ->
//                value.data = it.first().sxxx
                value.data = it.data[0].sxxx
                value.code = BaseEntity.ok
                LoggerManager.e("getSxhList 请求成功" )
            })
        }, {
            LoggerManager.e("getSxhList 修改失败 ${it.message}" )
            requestStatusLiveData.postValue(BaseEntity<List<Sxxx>>().also {value ->
                value.data = null
                value.code = BaseEntity.err
            })
        }))
    }

    /**
     * 清空任务容器
     */
    override fun onCleared() {
        super.onCleared()
        mCompositeDisposable.dispose()
    }
}